/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package as24gc.csv;

import as24gc.db.Vehicles;
import com.file.FileRW;
import java.util.List;

/**
 *
 * @author nico.vassallo
 */
public class CsvFile {

    private String fileName;
    private String path;
    private List vehiclesList;
    private String lineCsvContent;

    /*public CsvFile(){ }*/
    public CsvFile(String fileName, String path, List vehiclesList) {
        this.fileName = fileName;
        this.path = path;
        this.vehiclesList = vehiclesList;
        this.lineCsvContent="";
    }

    public void generateCsvContent() {
        for (int i = 0; i < this.getVehiclesList().size(); i++) {
            System.out.println("generateCsvContentOfVehicles[" + i + "]: )" + this.getVehiclesList().get(i));
            CsvLine csvLine = new CsvLine();
            csvLine.setVehicleToLine((Vehicles) this.getVehiclesList().get(i));
            this.setLineCsvContent(this.getLineCsvContent() + csvLine.getLine());
            this.setLineCsvContent(this.getLineCsvContent() + "\n");
        }
        System.out.println("\nCONTENT:\n"+this.getLineCsvContent());
    }

    public int writeFileOnFileSystem() {
        int result = 0;
        if (this.getLineCsvContent() == null || this.getLineCsvContent().length()<=1 ) {
            this.generateCsvContent();
        }
        result = FileRW.getInstance().writeOnF(this.getPath() + this.getFileName(), this.getLineCsvContent(), true);
        System.out.println("_File Created: "+result+" to path: " + this.getPath() + this.getFileName());
        return result;

    }

    public List getVehiclesList() {
        return vehiclesList;
    }

    public void setVehiclesList(List vehiclesList) {
        this.vehiclesList = vehiclesList;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getLineCsvContent() {
        return lineCsvContent;
    }

    public void setLineCsvContent(String lineCsvContent) {
        this.lineCsvContent = lineCsvContent;
    }
}
